import config from "./config.js";
export default {
	http(method, url, data, isLoading) { 
		const userInfo = uni.getStorageSync('userInfo');
		Object.assign(data, {  })
		return new Promise((resolve, reject) => {
			isLoading && uni.showLoading({ title: '加载中...' });
			var ul = (data.host ? data.host : config.httpBaseUrl()) + url
			var sendDate = (new Date()).getTime();
			uni.request({
				method: method.toUpperCase(),
				url: ul,
				data: data,
				header: {
					'loginToken': userInfo.accessToken,
					'Content-Type': 'application/json;charset=UTF-8'
				},
				success: (res) => {
					var receiveDate = (new Date()).getTime();
					if (config.env != 'pro1') {
						console.log(url, "响应时间=", receiveDate - sendDate, 'ms');
						config.env != 'pro' && console.log("请求参数=", data);
						config.env != 'pro' && console.log("响应信息=", res.data);
					}
					resolve(res.data)
				},
				fail: (err) => {
					resolve(err.data);
				},
				complete() {
					isLoading && uni.hideLoading();
					resolve();
					return;
				}
			})
		})
	},
}
